package com.project.servlet;

import com.project.bean.ManBean;
import com.project.service.IManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class FindByIdServlet extends HttpServlet {
    @Autowired
    private IManService service;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        ManBean man = service.findById(Integer.parseInt(req.getParameter("id")));
        String str = "<form action ='update' method='post'>";
        str+="<input type='hidden' name='id' value='"+man.getId()+"'>";
        str+="姓名： "+man.getName()+"<br>";
        str+="生日： <input type='date' name='birthday' value='"+man.getBirthday()+"'><br>";
        str+="<input type='submit' value='提交'></form>";
        resp.getWriter().println(str);
    }
}
